import matplotlib.pyplot as plt
import networkx as nx
from matplotlib import rcParams

# 设置字体
rcParams['font.sans-serif'] = ['Microsoft YaHei', 'SimHei', 'Arial Unicode MS', 'sans-serif']
rcParams['axes.unicode_minus'] = False  # 解决负号显示问题

def draw_functional_flowchart():
    G = nx.DiGraph()

    # 添加节点
    G.add_node("用户注册")
    G.add_node("用户登录")
    G.add_node("行程管理")
    G.add_node("目的地管理")
    G.add_node("收藏与分享")

    # 添加边
    G.add_edges_from([
        ("用户注册", "用户登录"),
        ("用户登录", "行程管理"),
        ("用户登录", "目的地管理"),
        ("用户登录", "收藏与分享"),
        ("行程管理", "收藏与分享"),
        ("目的地管理", "收藏与分享"),
    ])

    pos = nx.spring_layout(G)
    nx.draw(G, pos, with_labels=True, node_size=3000, node_color='lightblue', font_size=10, font_weight='bold', edge_color='gray')
    plt.title('功能需求流程图')
    plt.savefig('图2.1_功能需求流程图.png')
    plt.close()

def draw_test_results_chart():
    categories = ['功能完整性', '性能指标']
    results = [95, 90]  # 假设的测试结果百分比

    plt.bar(categories, results, color=['skyblue', 'lightgreen'])
    plt.ylim(0, 100)
    plt.ylabel('百分比')
    plt.title('测试结果汇总')
    plt.savefig('表5.1_测试结果汇总.png')
    plt.close()

def draw_improvement_suggestions_chart():
    labels = ['用户界面优化', '推荐算法提升', '数据安全性加强', '功能模块扩展']
    sizes = [25, 25, 25, 25]  # 假设的改进建议分布

    plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140)
    plt.axis('equal')
    plt.title('系统改进建议分布')
    plt.savefig('图6.1_系统改进建议图.png')
    plt.close()

if __name__ == "__main__":
    draw_functional_flowchart()
    draw_test_results_chart()
    draw_improvement_suggestions_chart() 